import type { User } from '@/types/user'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
  'user',
  () => {
    // 用户信息
    const user = ref<User | null>(null)
    // 设置用户
    const setUser = (u: User) => {
      user.value = u
    }
    // 删除用户
    const delUser = () => {
      user.value = null
    }

    // 回调地址
    const returnUrl = ref('')
    // 设置回调地址
    const setUrl = (url: string) => returnUrl.value = url

    return {
      user,
      setUser,
      delUser,
      returnUrl,
      setUrl
    }
  },
  {
    // 配置持久化存储
    persist: {
      key: 'comsult-patient-web6',
      // storage: sessionStorage
    }
  }
)
